<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['order']['tab'], 'pay');?>
		</div>
	</div>
</div>

<form method="get" class="form-inline m-b-xs" action="<?php echo url('order-pay');?>">
	<div class="row">
		<div class="col-lg-3">
			<div class="form-group" style="width:100%;">
				<select name="status" class="form-control" style="width:100%;">
					<option value="-1">全部</option>
					<option value="0" <?php if($status==0){echo 'selected';} ?>>未付款</option>
					<option value="1" <?php if($status==1){echo 'selected';} ?>>已付款</option>
				</select>
			</div>
		</div>
		<div class="col-lg-3">
			<div class="form-group" style="width:100%;">
				<select class="form-control" name="channel" style="width:100%;">
					<option value="0">全部通道</option>
					<?php foreach($channels as $c){ ?>
					<option value="<?php echo $c['id'];?>" <?php if($channel==$c['id']){echo 'selected';} ?>><?php echo $c['name'];?></option>
					<?php } ?>
				</select>
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="merchant" placeholder="商户订单号" value="<?php echo $merchant?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="plat" placeholder="平台订单号" value="<?php echo $plat;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="order_username" placeholder="商户帐号" value="<?php echo $order_username;?>" size="15" style="width:100%;">
			</div>
		</div>
	</div>
	<div class="row" style="margin-top:5px;">
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="money_start" placeholder="起始金额" value="<?php echo $money_start;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="money_end" placeholder="结束金额" value="<?php echo $money_end;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-5">
			<div class="form-group">
				<div class="input-group" style="background-color:#fff;">
					<span class="input-group-addon"><i class="icon icon-calendar"></i></span>
					<input type="text" name="fdate" class="form_datetime form-control" value="<?php echo $fdate;?>">
					<span class="input-group-addon">至</span>
					<input type="text" name="tdate" class="form_datetime form-control" value="<?php echo $tdate;?>">
				</div>
			</div>
		</div>
		<div class="col-lg-2">
			<button type="submit" class="btn btn-success" style="width:100%;">
				<i class="icon icon-search"></i>
				立即查询
			</button>
		</div>
		<div class="col-lg-1">
			<a class="btn btn-info" href="<?php echo url('order-pay').$param.'&export=1';?>">导出</a>
		</div>
	</div>
</form>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">商户帐号</th>
							<th class="text-center">通道</th>
							<th class="text-center">商户单号</th>
							<th class="text-center">平台单号</th>
							<th class="text-center">金额</th>
							<th class="text-center">支付金额</th>
							<th class="text-center">订单状态</th>
							<th class="text-center">通知状态</th>
                          	<th class="text-center">时间</th>
							<th class="text-center">操作</th>
							<th class="text-center">商户/代理/平台</th>
						</tr>
					</thead>
					<tbody id="userlist">
						<?php if($log){foreach($log as $l){ ?>
						<tr uid="<?php echo $l['id']; ?>">
							<td class="text-center"><?php echo $l['username']; ?></td>
							<td class="text-center"><?php echo $l['channel']; ?></td>
							<td class="text-center">
                            	<a href="javascript:;" onclick="$(this).parent().find('div').toggle()">显示</a>
								<div style="display:none;"><?php echo $l['order_merchant']; ?></div>	
                          	</td>
							<td class="text-center">
                            	<a href="javascript:;" onclick="$(this).parent().find('div').toggle()">显示</a>
								<div style="display:none;"><?php echo $l['order_plat']; ?></div>	
                          	</td>
							<td class="text-center"><?php echo round($l['coin'],2); ?> </td>
							<td class="text-center"><?php echo round($l['coin_pay'],2); ?> </td>							
							<td class="text-center"><?php echo $l['status']==1?'<b style="color:#0074d9;">已付款</b>':'未付款'; ?></td>
							<td class="text-center"><?php echo $l['notice_status']==1?'<b style="color:#0074d9;">已通知</b>':'未通知'; ?></td>
                          	<td class="text-center"><?php echo date('m-d H:i:s', $l['time']);?></td>
							<td class="text-center">
								<?php if($l['status']==1){ ?>
								<a href="javascript:;" class="re-notice" style="color: #00a2d4" data-href="<?php echo url("order-redo-notice-$l[id]"); ?>">通知</a>
								<?php }else{?>
								<a href="javascript:;" class="re-pay" data-toggle="modal" data-target="#myModal" data-href="<?php echo url("order-redo-pay-$l[id]"); ?>">付款</a>
								<?php }?>
							</td>
							<td class="text-center"><?php echo round($l['coin_merchant'],3).'/'.round($l['coin_proxy'],3).'/'.round($l['coin_plat'],3);?></td>
						</tr>
						<?php }} ?>
                      	<tr>
                          	<td class="text-center" colspan="4">合计</td>
                          	<td class="text-center"><?php echo round($total['coin_total'], 2); ?> </td>
                          	<td class="text-center"><?php echo round($total['coin_pay_total'], 2); ?> </td>
							<td class="text-center" colspan="4">&nbsp;</td>
                          	<td class="text-center"><?php echo round($total['coin_merchant'], 3).'/'.round($total['coin_proxy'], 3).'/'.round($total['coin_plat'], 3);?></td>
                        </tr>
					</tbody>
				</table>
			</div>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
			<div class="modal-body"><input type="hidden" id="data-href" value=""><input type="password" class="form-control" id="passcode" name="passcode" value="" placeholder="安全码"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="re-pay">确认付款</button>
			</div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<link rel="stylesheet" href="../view/css/datetimepicker.css?r=1">
<script src="../view/js/datetimepicker.js?r=1" type="text/javascript"></script>

<script>
//日期插件
$(".form_datetime").datetimepicker({
	language:  'zh',
	format: 'yyyy-mm-dd hh:ii:ss',//显示格式
	todayHighlight: 1,//今天高亮
	minView: 'hour',//设置只显示到月份
	startView: 'month',
	forceParse: 0,
	autoclose: 1//选择后自动关闭
});

var jbody = $("#userbody");
var jconfirm = $("#confirm");
var jsearch = $("#search");
var jsrchtype = $("#srchtype");
var jkeyword = $('#keyword');
var juserlist = $('#userlist');

jsearch.on('click', function(){
	var srchtype = jsrchtype.val();
	srchtype = srchtype ? srchtype : 'uid';
	var keyword = $("#keyword").val();
	var url = xn.url('user-list-'+srchtype+'-'+keyword+'-1');
	window.location = url;
});
jkeyword.on('keydown', function(e) {
	if(e.keyCode == 13) jsearch.trigger('click');
});

// 重新发送通知
$('.re-notice').click(function(){
	if(confirm('确认重新发送通知吗？')){
		$.xpost($(this).attr('data-href'), function(code, message){
			$.alert(message);
			if(code==1) setTimeout(function(){window.location.reload();}, 1500);
		});
	}
});

// 重新付款
$('.re-pay').click(function(){
	$('#data-href').val($(this).attr('data-href'));
});
$('#re-pay').click(function(){
	$.xpost($('#data-href').val(), {passcode:$('#passcode').val()}, function(code, message){
		$.alert(message);
		if(code==1) setTimeout(function(){window.location.reload();}, 1500);
	});
});

// 删除选中的用户
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的用户");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		$.xpost(xn.url('order-delete'), {id:uid}, function(code, message) {
			if(code != 0) return $.alert(message);
			jtr.remove();
		});
	});
});

$('#nav_pc li.order, #nav_mobile li.order').tab('show');
</script>